import matplotlib.pyplot as plt
import re
import sys

log_path = '../_save/on_person_car_2021_10_08Fri1554/log.txt'

regexp = re.compile(r'training loss = (\d+\.?\d*),')

cost_his = []
with open(log_path, 'r') as f:
    lines = f.readlines()
    for line in lines:
        matcher = regexp.search(line)
        if matcher is not None:
            number_str = matcher[1]
            try:
                cost = float(number_str)
                cost_his.append(cost)
            except:
                print(f'Error to parse {number_str} to float.', file=sys.stderr)

plt.figure(figsize=[14, 6])
# plt.plot(cost_his[-500:])
plt.plot(cost_his)
plt.show()
